package com.wd.live.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 过境千帆
 * @name  直播fragment的adapter
 * @time 2021/6/2 9:57
 * @chang time
 */
public class LiveFragmentPageAdapter extends FragmentPagerAdapter {

    private String[] tables = {"关注", "推荐", "直播","地图"};
    private List<Fragment> fragments ;

    public LiveFragmentPageAdapter(@NonNull @NotNull FragmentManager fm, int behavior) {
        super(fm, behavior);
    }

    public void setData(List<Fragment> fragment){
        if (fragments == null){
            fragments = new ArrayList<>();
        }
        fragments.addAll(fragment);
        notifyDataSetChanged();
    }
    @NonNull

    @NotNull
    @Override
    public Fragment getItem(int position) {
        if (fragments!=null &&fragments.size()>0) {
            return fragments.get(position);
        }
        return null;
    }

    @Override
    public int getCount() {
        if (fragments != null && fragments.size() >0){
            return fragments.size();
        }
        return 0;
    }

    @Override
    public CharSequence getPageTitle(int position)
    {
        return tables[position];
    }
}
